package sfeir.gwt.ergosoom.server;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.Singleton;

@SuppressWarnings("serial")
@Singleton
public class ViewProfile extends HttpServlet {


    private final Injector injector;

    @Inject
    public ViewProfile(Injector injector) {
        this.injector = injector;
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        /*String username = req.getPathInfo();
        if (username != null) {
            username = username.replace('/', ' ').trim();
            req.setAttribute("username", username);
        }
        if (username.endsWith("_logout")) {*/
            req.getSession().invalidate();
            resp.sendRedirect("/");
            return;
        /*}

        RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/ViewProfile.jsp");
        dispatcher.forward(req, resp);*/
    }

//    @Override
//    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        String path = req.getPathInfo();
//        if ("/_login".equals(path)) {
//            ProfileService ps = injector.getInstance(ProfileService.class);
//            Profile p = ps.login(req.getParameter("login"), DigestUtils.toMd5(req.getParameter("pass")));
//            if (null != p) {
//                req.getSession(true).setAttribute("ergosoom.login", p.getEmail());
//                req.getSession().setAttribute("ergosoom.pass", req.getParameter("pass"));
//                resp.sendRedirect("/EditProfile.jsp");
////                req.getRequestDispatcher("/EditProfile.jsp").forward(req, resp);
//            } else {
////                req.setAttribute("ergosoom_error", "Bad credentials");
//                resp.sendRedirect("/ErgoSoom.jsp?ergosoom_error=Bad%20Credentials");
//            }
//            return;
//        }
//    }
}
